<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nginx 大文件传输完全指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e293b;
            border-radius: 12px;
            overflow: hidden;
            position: relative;
        }
        .code-header {
            background: #334155;
            padding: 8px 16px;
            font-size: 12px;
            color: #94a3b8;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .code-content {
            padding: 20px;
            overflow-x: auto;
        }
        .code-content pre {
            margin: 0;
            color: #e2e8f0;
            font-family: 'Consolas', 'Monaco', monospace;
            font-size: 14px;
            line-height: 1.6;
        }
        .section-title {
            position: relative;
            display: inline-block;
        }
        .section-title::after {
            content: '';
            position: absolute;
            bottom: -8px;
            left: 0;
            width: 60px;
            height: 4px;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        .highlight-box {
            background: linear-gradient(135deg, #ffeaa7 0%, #fab1a0 100%);
            border-radius: 8px;
            padding: 2px 8px;
            display: inline-block;
            color: #2d3436;
            font-weight: 500;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .floating-icon {
            animation: float 3s ease-in-out infinite;
        }
        @keyframes float {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center">
            <div class="floating-icon inline-block mb-6">
                <i class="fas fa-server text-6xl opacity-90"></i>
            </div>
            <h1 class="text-5xl md:text-6xl font-bold mb-6">Nginx 大文件传输完全指南</h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                掌握 Nginx 处理大文件上传与下载的核心技术，优化性能，提升用户体验
            </p>
            <div class="mt-10 flex justify-center space-x-6">
                <div class="text-center">
                    <i class="fas fa-upload text-3xl mb-2"></i>
                    <p class="text-sm">高效上传</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-download text-3xl mb-2"></i>
                    <p class="text-sm">快速下载</p>
                </div>
                <div class="text-center">
                    <i class="fas fa-chart-line text-3xl mb-2"></i>
                    <p class="text-sm">性能优化</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction Card -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 card-hover">
            <p class="text-lg leading-relaxed text-gray-700">
                在 Nginx 中处理大文件上传和下载需要考虑多个方面，包括配置上传限制、优化性能、处理文件传输等。本指南将带您深入了解每个关键配置，助您构建高性能的文件传输系统。
            </p>
        </div>

        <!-- Visualization -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-2xl font-bold mb-6 gradient-text">系统架构概览</h2>
            <div class="mermaid">
                graph TB
                    A[客户端] -->|大文件上传| B[Nginx]
                    B --> C[上传配置]
                    C --> D[client_max_body_size]
                    C --> E[client_body_timeout]
                    B --> F[下载配置]
                    F --> G[sendfile]
                    F --> H[tcp_nopush/tcp_nodelay]
                    F --> I[断点续传]
                    B --> J[监控日志]
                    J --> K[access_log]
                    J --> L[log_format]
                    
                    style A fill:#667eea,stroke:#fff,color:#fff
                    style B fill:#764ba2,stroke:#fff,color:#fff
                    style C fill:#ffeaa7,stroke:#333
                    style F fill:#fab1a0,stroke:#333
                    style J fill:#74b9ff,stroke:#333
            </div>
        </div>

        <!-- Upload Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">
                <i class="fas fa-cloud-upload-alt mr-3 text-purple-600"></i>大文件上传
            </h2>

            <!-- Upload Size Configuration -->
            <div class="bg-white rounded-2xl shadow-lg p-8 mb-8 card-hover">
                <h3 class="text-xl font-bold mb-4 flex items-center">
                    <i class="fas fa-cog mr-3 text-purple-500"></i>
                    配置上传文件大小限制
                </h3>
                <p class="text-gray-700 mb-6 leading-relaxed">
                    Nginx 默认对上传文件有大小限制，这个限制可以通过 <span class="highlight-box">client_max_body_size</span> 指令进行配置。该指令指定了客户端请求体的最大大小，包括文件上传。
                </p>
                <div class="code-block">
                    <div class="code-header">
                        <span><i class="fas fa-code mr-2"></i>nginx.conf</span>
                        <i class="fas fa-copy cursor-pointer hover:text-white"></i>
                    </div>
                    <div class="code-content">
                        <pre>http {
    # 设置最大上传文件大小为 100MB
    client_max_body_size 100M;

    # 其他配置...
}</pre>
                    </div>
                </div>
                <div class="mt-6 bg-purple-50 border-l-4 border-purple-500 p-4 rounded">
                    <p class="text-sm text-gray-700">
                        <i class="fas fa-info-circle mr-2 text-purple-500"></i>
                        <strong>提示：</strong>如果上传的文件超过设定大小，Nginx 将返回 <code class="bg-gray-200 px-2 py-1 rounded text-sm">413 Request Entity Too Large</code> 错误。
                    </p>
                </div>
            </div>

            <!-- Timeout Configuration -->
            <div class="bg-white rounded-2xl shadow-lg p-8 mb-8 card-hover">
                <h3 class="text-xl font-bold mb-4 flex items-center">
                    <i class="fas fa-clock mr-3 text-purple-500"></i>
                    处理上传过程中的超时
                </h3>
                <p class="text-gray-700 mb-6 leading-relaxed">
                    长时间的上传过程可能会超时。可以通过 <span class="highlight-box">client_body_timeout</span> 和 <span class="highlight-box">proxy_read_timeout</span> 指令来调整超时设置。
                </p>
                <div class="code-block">
                    <div class="code-header">
                        <span><i class="fas fa-code mr-2"></i>nginx.conf</span>
                        <i class="fas fa-copy cursor-pointer hover:text-white"></i>
                    </div>
                    <div class="code-content">
                        <pre>http {
    # 设置客户端请求体读取超时为 300 秒
    client_body_timeout 300s;

    # 其他配置...
}</pre>
                    </div>
                </div>
            </div>

            <!-- Performance Optimization -->
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <h3 class="text-xl font-bold mb-4 flex items-center">
                    <i class="fas fa-rocket mr-3 text-purple-500"></i>
                    优化上传性能
                </h3>
                <p class="text-gray-700 leading-relaxed">
                    对于大文件上传，可以考虑使用异步上传或分块上传的方式来提高性能。虽然 Nginx 本身并不直接支持这些功能，但可以通过配合前端上传组件实现：
                </p>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mt-6">
                    <div class="bg-gradient-to-br from-purple-50 to-pink-50 p-6 rounded-xl">
                        <i class="fas fa-puzzle-piece text-3xl text-purple-600 mb-3"></i>
                        <h4 class="font-bold mb-2">Dropzone.js</h4>
                        <p class="text-sm text-gray-600">支持拖拽上传和分块传输</p>
                    </div>
                    <div class="bg-gradient-to-br from-blue-50 to-purple-50 p-6 rounded-xl">
                        <i class="fas fa-cloud text-3xl text-blue-600 mb-3"></i>
                        <h4 class="font-bold mb-2">FineUploader</h4>
                        <p class="text-sm text-gray-600">提供断点续传和并发上传</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Download Section -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 section-title">
                <i class="fas fa-cloud-download-alt mr-3 text-blue-600"></i>大文件下载
            </h2>

            <!-- File Transfer Configuration -->
            <div class="bg-white rounded-2xl shadow-lg p-8 mb-8 card-hover">
                <h3 class="text-xl font-bold mb-4 flex items-center">
                    <i class="fas fa-exchange-alt mr-3 text-blue-500"></i>
                    配置文件传输相关设置
                </h3>
                <p class="text-gray-700 mb-6 leading-relaxed">
                    为了优化大文件下载的性能，可以通过以下关键设置：
                </p>
                
                <!-- Sendfile -->
                <div class="mb-6">
                    <h4 class="font-bold mb-3 flex items-center">
                        <i class="fas fa-paper-plane mr-2 text-blue-400"></i>
                        启用 Sendfile
                    </h4>
                    <p class="text-gray-600 mb-4">启用高效的文件传输模式，利用操作系统的 sendfile() 系统调用来提高文件传输性能。</p>
                    <div class="code-block">
                        <div class="code-header">
                            <span><i class="fas fa-code mr-2"></i>nginx.conf</span>
                            <i class="fas fa-copy cursor-pointer hover:text-white"></i>
                        </div>
                        <div class="code-content">
                            <pre>http {
    # 启用 sendfile
    sendfile on;

    # 其他配置...
}</pre>
                        </div>
                    </div>
                </div>

                <!-- TCP Optimization -->
                <div class="mb-6">
                    <h4 class="font-bold mb-3 flex items-center">
                        <i class="fas fa-network-wired mr-2 text-blue-400"></i>
                        TCP 优化
                    </h4>
                    <p class="text-gray-600 mb-4">控制 TCP 套接字的行为，优化网络传输性能。</p>
                    <div class="code-block">
                        <div class="code-header">
                            <span><i class="fas fa-code mr-2"></i>nginx.conf</span>
                            <i class="fas fa-copy cursor-pointer hover:text-white"></i>
                        </div>
                        <div class="code-content">
                            <pre